<meta charset="utf-8" />
<div class="breadcrumbs" id="breadcrumbs">
	<ul class="breadcrumb">
		<li><i class="ace-icon fa fa-home home-icon"></i> <a href="index">主数据管理</a>
		</li>

		<li><span>物料管理</span></li>
	</ul>
	<!-- /.breadcrumb -->
</div>

<div class="page-content">
	<div class="row">
		<div class="col-xs-12">
			<div class="clearfix"></div>
			<div class="table-header">物料管理</div>
			<div>
				<div id="dynamic-table_wrapper"
					class="dataTables_wrapper form-inline no-footer">
					<div class="row">
						<div class="widget">
							<div class="widget-main">
								<form class="form-inline" id="selefrom" action="wlsjgl/sele"
									method="post">
									<input type="search" style="width:180px;height:30px "
										; class="form-control input-sm" placeholder="输入查询内容"
										aria-controls="dynamic-table" name="selevalue" id="hhh1">
									<select name="seletype" aria-controls="dynamic-table" id="selectValue"
										style="height:30px; width: 180px " ; class="form-control">
										<option value="wlbm">物料编码</option>
										<option value="wlxh">物料型号</option>
										<option value="zlbm">子料编码</option>
										<option value="zlxh">子料型号</option>
										<option value="gg">规格/型号</option>
									</select>
									<button id="selectfromsb" style="height:30px "
										class="btn btn-info btn-sm">查询</button>
										
									<button id="selectfromcz" style="height:30px "
										class="btn btn-info btn-sm">重置</button>
								</form>
							</div>
							<div class="pull-left" style="margin: 0px 0px 0px 17px;">
								<button onclick="javascript:addwlglsj()" class="btn btn-info btn-sm" style="margin: 0px 8px 0px 0px;">添加</button>
								<button onclick="" class="btn btn-info btn-sm" style="margin: 0px 8px 0px 0px;">删除</button>
								<button onclick="" class="btn btn-info btn-sm" style="margin: 0px 8px 0px 0px;">导入</button>
								<button onclick="" class="btn btn-info btn-sm" style="margin: 0px 8px 0px 0px;">导出</button>
							</div>
						</div>
					</div>
					<div style="overflow-x: scroll;">
						<table
							class="table table-striped table-bordered table-hover dataTable no-footer DTTT_selectable"
							id="dynamic-table" role="grid"
							aria-describedby="dynamic-table_info">
							<thead>
								<tr role="row">
									<th class="center" style="width:9px; "><label> <input type="checkbox" class="ace" /> <span class="lbl"></span></label></th>
									<th class="hidden-480" style="width: 20px">物料编码</th>
									<th class="hidden-320">物料名称</th>
									<th>规格型号</th>
									<th>单位</th>
									<th>品牌</th>
									<th>供应商</th>
									<th>供应商编码</th>
									<th>物料类型</th>
									<th>物料等级</th>
									<th>采购类型</th>
									<th>储存期</th>
									<th>质保期</th>
									<th>库存</th>
									<th>最低库存</th>
									<th>最高库存</th>
									<th>物料组</th>
									<th>批次管理</th>
									<th>核心物料</th>
									<th>是否检验</th>
									<th>生产周期</th>
									<th>采购周期</th>
									<th>可替换物料</th>
									<th>参考文档</th>
									<th>损耗率</th>
									<th>物料状态</th>
									<th>备注</th>
								</tr>
							</thead>
							<tbody id="wlsjtc">
							</tbody>
						</table>
					</div>
					<div class="row">
						<div class="col-xs-12 col-md-12">
							<div class=" pull-left">
								<label>显示<select name="dynamic-table_length"
									aria-controls="dynamic-table" class="form-control input-sm" id="sel">
									    <option value="10">10</option>
										<option value="20">20</option>
										<option value="50">50</option>
										<option value="100">100</option>
								</select> 条记录</label>
							</div>

							<div class="dataTables_paginate paging_simple_numbers ">
								<ul class="pagination" id="dynamic-table_paginate111">
														</ul>
								<div class="dataTables_paginate paging_simple_numbers">
									<div class="laypage_main laypageskin_molv" id="laypage_3">
										<span class="laypage_curr" style="background-color:#2283C5">1</span><span
											class="laypage_total"><label>到第</label><input max="1"
											min="1" class="laypage_skip" type="number"><label>页</label>
											<button type="button" class="laypage_btn">
												确定
												<tton>
										< /span>
									</div>
								</div>

							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>


<!--添加用户-->
<div class="hide" id="add">
	<div class="col-xs-1"></div>
	<div class="col-xs-9">
		<form method="post" id="addFrom">
			<!--<table>
				<th>物料编码：</th>
				<th><input type="text" name="wlbm"/></th>
			</table>-->
			<table class="layui-table" lay-data="{height:315, url:'/demo/table/user/', page:true, id:'test'}" lay-filter="test">
			  <thead>
			    <tr>
			      <td lay-data="{field:'wlbm', width:80}">物料编号</td>
			      <td><input type="text" name="wlbm"/></td>
			      <td lay-data="{field:'wlmc', width:80}">物料名称</td>
			      <td><input type="text" name="wlmc"/></td>
			    </tr>
			    <tr>
			      <td lay-data="{field:'ggxh', width:80}">规格型号</td>
			      <td><input type="text" name="wlbm"/></td>
			      <td lay-data="{field:'pp', width:80}">品牌</td>
			      <td><input type="text" name="pp"/></td>
			    </tr>
			    <tr>
			      <td lay-data="{field:'dw', width:80}">单位</td>
			      <td><input type="text" name="dw"/></td>
			      <td lay-data="{field:'wllx', width:80}">物料类型</td>
			      <td><input type="text" name="wllx"/></td>
			    </tr>
			    <tr>
			      <td lay-data="{field:'wldj', width:80}">物料等级</td>
			      <td>
			      	<select name="wldj">
			      		<option>请选择物料等级</option>
			      		<option>一级</option>
			      		<option>二级</option>
			      		<option>三级</option>
			      		<option>特级</option>
			      	</select>
			      </td>
			      <td lay-data="{field:'wllx', width:80}">是否外购</td>
			      <td>
			      	<select>
			      		<option>否</option>
			      		<option>是</option>
			      	</select>
			      </td>
			    </tr>
			    <tr>
			      <td lay-data="{field:'zbq', width:80}">质保期</td>
			      <td><input type="text" name="zbq"/></td>
			      <td lay-data="{field:'ccq', width:80}">储存期</td>
			      <td><input type="ccq" name="ccq"/></td>
			    </tr>
			    <tr>
			      <td lay-data="{field:'ck', width:80}">仓库</td>
			      <td name="ck">
			      	<select>
			      	   <option>仓库1</option>
			      	   <option>仓库2</option>
			      	   <option>仓库3</option>
			      	   <option>仓库4</option>
			        </select>
			      </td>
			      <td lay-data="{field:'wllx', width:80}">最高库存</td>
			      <td>
			      	<input name="zdkc" type="text"/>
			      </td>
			    </tr>
			    <tr>
			      <td lay-data="{field:'wlz', width:80}">物料组</td>
			      <td>
			      	<select name="wlz">
			      		<option>物料组1</option>
			      		<option>物料组3</option>
			      		<option>物料组4</option>
			      	</select>
			      </td>
			      <td lay-data="{field:'pcgl', width:80}">是否批次管理</td>
			      <td>
			      	<section>
			      		<option>是</option>
			      		<option>否</option>
			      	</section>
			      </td>
			    </tr>
			    <tr>
			      <td lay-data="{field:'sfjy', width:80}">是否检验</td>
			      <td>
			      	<section>
			      		<option>是</option>
			      		<option>否</option>
			      	</section>
			      </td>
			      <td lay-data="{field:'cgzq', width:80}">采购周期</td>
			      <td><input type="text"/></td>
			    </tr>
			    <tr>
			    	<td lay-data="{field:'cjbh', width:80}">厂家编号</td>
			    	<td>
			    		<select>
			    			<option>编号1</option>
			    			<option>编号2</option>
			    			<option>编号3</option>
			    		</select>
			    	</td>
			    </tr>
			  </thead>
			</table>
		</form>
	</div>
</div>
<!-- 更改每页显示数据的数目 -->
<script type="text/javascript">
	var sel = document.getElementById("sel");
	sel.onchange = function() {
		/* alert(sel.options[sel.selectedIndex].value); */
		$.post("wlsjgl/gghs", {
			"def_number" : sel.options[sel.selectedIndex].value
		}, function(data) {
			pagedemo(1);
		});
	}
</script>

<script type="text/javascript">
	pagedemo(1);
	function pagedemo(n) {

		$.post("wlsjgl/pagedemo", {
			"pageNumber" : n,
			"pch" : $("#pch").val()
		}, function(data) {
			pack(data.list); //调用下面pack()方法，填充表格数据

			if (data.totalPage == 1) {
				$("#dynamic-table_paginate111").addClass("hide");
				$("#laypage_3").removeClass("hide");
			} else {
				$("#laypage_3").addClass("hide");
				$("#dynamic-table_paginate111").removeClass("hide");
				laypage({
					cont : $('#dynamic-table_paginate111'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : data.totalPage, //总页数
					skip : true, //是否开启跳页
					skin : '#2283C5',//保持ace中间的样式
					first : 1,
					last : data.totalPage, //总页数，将尾页显示为总页数
					curr : data.pageNumber,//当前页
					groups : 5, //连续显示分页数
					jump : function(obj, first) {
						if (!first) { //一定要加此判断，否则初始时会无限刷新
							pagedemo(obj.curr);
						}
					}
				});
			}

		});
	}

	function pack(data) { //填充数据
		var dataStr = "";
		$.each(data, function(i, v) {
			dataStr += packlist(v);
		});
		$("#wlsjtc").html(dataStr);
	}

	function packlist(v) {
		var dataStr = "";
		dataStr += '<tr>';
		dataStr += '<td class="center" style="width:9px; "><label> <input type="checkbox"class="ace" /> <span class="lbl"></span></label></td>';
		dataStr += '<td><a>' + v.wlbm + '<a></td>';
		dataStr += '<td>' + v.wlmc + '</td>';
		dataStr += '<td>' + v.ggxh + '</td>';
		dataStr += '<td>' + v.dw + '</td>';
		dataStr += '<td>' + v.pp + '</td>';
		dataStr += '<td>' + v.gys + '</td>';
		dataStr += '<td>' + v.gysbm + '</td>';
		dataStr += '<td>' + v.wllx + '</td>';
		dataStr += '<td>' + v.wldj + '</td>';
		dataStr += '<td>' + v.cglx + '</td>';
		dataStr += '<td>' + v.ccq + '</td>';
		dataStr += '<td>' + v.zbq + '</td>';
		dataStr += '<td>' + v.kc + '</td>';
		dataStr += '<td>' + v.zbkc + '</td>';
		dataStr += '<td>' + v.zgkc + '</td>';
		dataStr += '<td>' + v.wlz + '</td>';
		dataStr += '<td>' + v.pcgl + '</td>';
		dataStr += '<td>' + v.hxwl + '</td>';
		dataStr += '<td>' + v.sfjy + '</td>';
		dataStr += '<td>' + v.sczq + '</td>';
		dataStr += '<td>' + v.cgzq + '</td>';
		dataStr += '<td>' + v.kthwl + '</td>';
		dataStr += '<td>' + v.ckwd + '</td>';
		dataStr += '<td>' + v.shl + '</td>';
		dataStr += '<td>' + v.wlzt + '</td>';
		dataStr += '<td>' + v.bz + '</td>';
		dataStr += '</tr>';
		return dataStr;
	};

	/* 撤销查询 */
	$("#selectfromcz").click(function() {
		document.getElementById("hhh1").value = "";
		$.post("wlsjgl/sele", $("#selefrom").serialize(), function(data) {
			pagedemo(1);
		})
		return false;
	});
    //查询选中的类型数据
    $("#selectfromsb").click(function() {
    	var wlcxType = document.getElementById('selectValue').value;
    	console.log(wlcxType);
    	//var value = obj.options[index].value; // 选中值
		$.post("wlsjgl/sele",
		"cxType": wlType,
		$("#selefrom").serialize(), function(data) {
			pagedemo(1);
	});
	
	


	//错误提示(传入错误信息)
	function errorMsg(errorInfo) {
		layer.confirm(errorInfo, {
			btn : [ '确定' ]
		//按钮
		}, function(index) {
			layer.close(index);
		});
	}
	//测试

</script>
<script type="text/javascript">
	function updateUser(id,uname,name,position,email,hiredate,education,age,gender) {
		document.getElementById("uup").reset();
		$("#user_id").val(id);
		$("#user_username").val(uname);
		$("#user_name").val(name);
		$("#user_position").val(position);
		$("#user_email").val(email);
		$("#user_hiredate").val(hiredate);
		var age_ = document.getElementById("age"+age);
		age_.selected = 'selected';
		var edu = document.getElementById("cz");;
		if(education=='高中') edu = document.getElementById("gz");
		else if(education=='专科') edu = document.getElementById("zk");
		else if(education=='本科') edu = document.getElementById("bk");
		else if(education=='硕士') edu = document.getElementById("ss");
		else if(education=='博士') edu = document.getElementById("bs");
		edu.selected = 'selected';
		if(gender=='男'){
			var sex1 = document.getElementById("男");
			sex1.setAttribute("checked", "checked");
		}
		if(gender=='女'){
			var sex2 = document.getElementById("_nv");
			sex2.setAttribute("checked", "checked");
		}
		$('#up').removeClass("hidden");
		userModel = layer.open({
			type : 1,
			shade : [ 0.5 ],
			title : '角色更新', //不显示标题
			area : [ '40%', '60%' ], //显示空间
			content : $('#up'), //捕获的元素
			btn : [ '更新', '取消' ],
			yes : function(index, layero) { //或者使用btn1
				var username = document.getElementById("user_username").value;
				var name = document.getElementById("user_name").value;
				var dept = document.getElementById("areaid").value;
				var role = document.getElementById("townid").value;
				var position = document.getElementById("user_position").value;
				var hiredate = document.getElementById("user_hiredate").value;
				var email = document.getElementById("user_email").value;
				errorMsg(role);
				if(username==""){
					errorMsg("用户名不能为空");
					return false;
				}
				if(name==""){
					errorMsg("姓名不能为空");
					return false;
				}
				if(dept==""){
					errorMsg("部门需要手动选择");
					return false;
				}
				 if(role==""){
					errorMsg("角色需要手动选择");
					return false;
				} 
				if(position==""){
					errorMsg("职位不能为空");
					return false;
				}
				if(hiredate==""){
					errorMsg("参加工作日期不能为空");
					return false;
				}
				if(email==""){
					errorMsg("电子邮箱不能为空");
					return false;
				}
				var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
				if(!myreg.test(email)){
					errorMsg("请输入正确的邮箱格式");
					return false;
				}
				
				$.post("users/update", $("#uup").serialize(), function(data) {
					if(data=="fail"){
						errorMsg("该用户名已存在，请重新输入");
						//return false;
					}else{
						layer.close(index);
						$('#up').addClass("hidden");
						pageChange(1);
						layer.msg("修改成功");
					}
					
					
					//document.getElementById("uup").submit();
				});
			},
			cancel : function(index) {
				layer.close(index);
				$('#up').addClass("hidden"); //取消继续隐藏
				layer.msg("已取消");
			},
		});
	};
</script>

<script type="text/javascript">
	function addwlglsj() {
		document.getElementById("pform").reset();
		$('#add').removeClass("hide");
		userModel = layer.open({
			type : 1,
			shade : [ 0.5 ],
			title : '角色添加', //不显示标题
			area : [ '40%', '80%' ], //显示空间
			content : $('#add'), //捕获的元素
			btn : [ '添加', '取消' ],
			yes : function(index, layero) { //或者使用btn1
				var username = document.getElementById("addusername").value;
				var password = document.getElementById("addpassword").value;
				var name = document.getElementById("addname").value;
				var dept = document.getElementById("areaid1").value;
				var role = document.getElementById("townid1").value;
				var position = document.getElementById("addposition").value;
				var hiredate = document.getElementById("addhiredate").value;
				var email = document.getElementById("addemail").value;
				
				if(username==""){
					errorMsg("用户名不能为空");
					return false;
				}
				if (escape(username).indexOf("%u") != -1){
					errorMsg("用户名不能包含汉字");
					return false;
				}
				if(password==""){
					errorMsg("密码不能为空");
					return false;
				}
				if(name==""){
					errorMsg("姓名不能为空");
					return false;
				}
				if(dept==""){
					errorMsg("部门需要手动选择");
					return false;
				}
				if(role==""){
					errorMsg("角色需要手动选择");
					return false;
				}
				if(position==""){
					errorMsg("职位不能为空");
					return false;
				}
				if(hiredate==""){
					errorMsg("参加工作日期不能为空");
					return false;
				}
				if(email==""){
					errorMsg("电子邮箱不能为空");
					return false;
				}
				var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
				if(!myreg.test(email)){
					errorMsg("请输入正确的邮箱格式");
					return false;
				}
				$.post("users/addUser", $("#pform").serialize(), function(data) {
					if(data=="fail"){
						errorMsg("该用户名已存在，请重新输入");
						//return false;
					}else{
						layer.close(index);
						$('#add').addClass("hide");
						pageChange(1);
						layer.msg("添加成功");
					}
					//document.getElementById("pform").submit();
				});
			},
			cancel : function(index) {
				layer.close(index);
				$('#add').addClass("hide"); //取消继续隐藏
				layer.msg("已取消");
			},
		});
	};
</script>